<?php

/**
 * OneClickShipmentResult.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Amazon Shipping API.
 *
 * The Amazon Shipping API is designed to support outbound shipping use cases both for orders originating on Amazon-owned marketplaces as well as external channels/marketplaces. With these APIs, you can request shipping rates, create shipments, cancel shipments, and track shipments.
 *
 * The version of the OpenAPI document: v2
 * Contact: swa-api-core@amazon.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\shipping\v2;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * OneClickShipmentResult Class Doc Comment.
 *
 * @category Class
 *
 * @description The payload for the OneClickShipment API.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class OneClickShipmentResult implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'OneClickShipmentResult';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'shipment_id' => 'string',
        'package_document_details' => '\SpApi\Model\shipping\v2\PackageDocumentDetail[]',
        'promise' => '\SpApi\Model\shipping\v2\Promise',
        'carrier' => '\SpApi\Model\shipping\v2\Carrier',
        'service' => '\SpApi\Model\shipping\v2\Service',
        'total_charge' => '\SpApi\Model\shipping\v2\Currency'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'shipment_id' => null,
        'package_document_details' => null,
        'promise' => null,
        'carrier' => null,
        'service' => null,
        'total_charge' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'shipment_id' => false,
        'package_document_details' => false,
        'promise' => false,
        'carrier' => false,
        'service' => false,
        'total_charge' => false,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'shipment_id' => 'shipmentId',
        'package_document_details' => 'packageDocumentDetails',
        'promise' => 'promise',
        'carrier' => 'carrier',
        'service' => 'service',
        'total_charge' => 'totalCharge',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'shipment_id' => 'setShipmentId',
        'package_document_details' => 'setPackageDocumentDetails',
        'promise' => 'setPromise',
        'carrier' => 'setCarrier',
        'service' => 'setService',
        'total_charge' => 'setTotalCharge',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'shipment_id' => 'getShipmentId',
        'package_document_details' => 'getPackageDocumentDetails',
        'promise' => 'getPromise',
        'carrier' => 'getCarrier',
        'service' => 'getService',
        'total_charge' => 'getTotalCharge',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('shipment_id', $data ?? [], null);
        $this->setIfExists('package_document_details', $data ?? [], null);
        $this->setIfExists('promise', $data ?? [], null);
        $this->setIfExists('carrier', $data ?? [], null);
        $this->setIfExists('service', $data ?? [], null);
        $this->setIfExists('total_charge', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['shipment_id']) {
            $invalidProperties[] = "'shipment_id' can't be null";
        }
        if (null === $this->container['package_document_details']) {
            $invalidProperties[] = "'package_document_details' can't be null";
        }
        if (null === $this->container['promise']) {
            $invalidProperties[] = "'promise' can't be null";
        }
        if (null === $this->container['carrier']) {
            $invalidProperties[] = "'carrier' can't be null";
        }
        if (null === $this->container['service']) {
            $invalidProperties[] = "'service' can't be null";
        }
        if (null === $this->container['total_charge']) {
            $invalidProperties[] = "'total_charge' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets shipment_id.
     */
    public function getShipmentId(): string
    {
        return $this->container['shipment_id'];
    }

    /**
     * Sets shipment_id.
     *
     * @param string $shipment_id the unique shipment identifier provided by a shipping service
     */
    public function setShipmentId(string $shipment_id): self
    {
        if (is_null($shipment_id)) {
            throw new \InvalidArgumentException('non-nullable shipment_id cannot be null');
        }
        $this->container['shipment_id'] = $shipment_id;

        return $this;
    }

    /**
     * Gets package_document_details.
     */
    public function getPackageDocumentDetails(): array
    {
        return $this->container['package_document_details'];
    }

    /**
     * Sets package_document_details.
     *
     * @param array $package_document_details a list of post-purchase details about a package that will be shipped using a shipping service
     */
    public function setPackageDocumentDetails(array $package_document_details): self
    {
        if (is_null($package_document_details)) {
            throw new \InvalidArgumentException('non-nullable package_document_details cannot be null');
        }
        $this->container['package_document_details'] = $package_document_details;

        return $this;
    }

    /**
     * Gets promise.
     */
    public function getPromise(): Promise
    {
        return $this->container['promise'];
    }

    /**
     * Sets promise.
     *
     * @param Promise $promise promise
     */
    public function setPromise(Promise $promise): self
    {
        if (is_null($promise)) {
            throw new \InvalidArgumentException('non-nullable promise cannot be null');
        }
        $this->container['promise'] = $promise;

        return $this;
    }

    /**
     * Gets carrier.
     */
    public function getCarrier(): Carrier
    {
        return $this->container['carrier'];
    }

    /**
     * Sets carrier.
     *
     * @param Carrier $carrier carrier
     */
    public function setCarrier(Carrier $carrier): self
    {
        if (is_null($carrier)) {
            throw new \InvalidArgumentException('non-nullable carrier cannot be null');
        }
        $this->container['carrier'] = $carrier;

        return $this;
    }

    /**
     * Gets service.
     */
    public function getService(): Service
    {
        return $this->container['service'];
    }

    /**
     * Sets service.
     *
     * @param Service $service service
     */
    public function setService(Service $service): self
    {
        if (is_null($service)) {
            throw new \InvalidArgumentException('non-nullable service cannot be null');
        }
        $this->container['service'] = $service;

        return $this;
    }

    /**
     * Gets total_charge.
     */
    public function getTotalCharge(): Currency
    {
        return $this->container['total_charge'];
    }

    /**
     * Sets total_charge.
     *
     * @param Currency $total_charge total_charge
     */
    public function setTotalCharge(Currency $total_charge): self
    {
        if (is_null($total_charge)) {
            throw new \InvalidArgumentException('non-nullable total_charge cannot be null');
        }
        $this->container['total_charge'] = $total_charge;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
